<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <el-row>
        <el-col :span="14">
          <el-input
            placeholder="请输入内容"
            v-model="queryInfo.query"
            clearable
            @clear="getOrdersList"
            @input="getOrdersList"
          >
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 表单数据 -->
      <el-table :data="ordersList" border stripe>
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="80"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款" width="90">
          <template slot-scope="scope">
            <el-button size="mini" type="danger" plain v-if="scope.row.pay_status===0">未付款</el-button>
            <el-button size="mini" type="success" v-else plain>已付款</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="80">
          <template slot-scope="scope">{{scope.row.is_send}}</template>
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="160">
          <template slot-scope="scope">{{scope.row.create_time|dateFormat}}</template>
        </el-table-column>
        <el-table-column label="操作" width="130">
          <template>
            <el-button type="primary" size="mini" icon="el-icon-edit" @click="editFrom"></el-button>
            <el-button type="success" size="mini" icon="el-icon-location" @click="physicaFrom"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[3,5, 10, 15]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
    <!-- 修改表单的对话框 -->
    <el-dialog title="提示" :visible.sync="editDialogVisible" width="50%">
      <el-form :model="editForm" :rules="editFormRules" ref="editFormRef" label-width="100px">
        <el-form-item label="省市区/县" prop="name1">
          <el-cascader v-model="editForm.name1" :options="cityDate"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="name2">
          <el-input v-model="editForm.name2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流信息的对话框 -->
    <el-dialog title="提示" :visible.sync="physicalDialogVisible" width="50%">
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in physicaList"
          :key="index"
          :timestamp="activity.time"
        >{{activity.context}}</el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityDate from "./citydata.js";
export default {
  data() {
    return {
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 10
      },
      //  总条数
      total: 0,
      // 订单管理列表数据
      ordersList: [],
      // 修改对话框的显示与隐藏
      editDialogVisible: false,
      // 修改对话框的数据
      editForm: {
        name1: [],
        name2: ""
      },
      // 验证规则
      editFormRules: {
        name1: [
          { required: true, message: "请选择省市区/县", trigger: "blur" }
        ],
        name2: [{ required: true, message: "请填写详细地址", trigger: "blur" }]
      },
      cityDate,
      // 物流信息的对话框显示与隐藏
      physicalDialogVisible: false,
      // 物流信息数据
      physicaList: []
    };
  },
  methods: {
    //   获取订单管理列表数据
    async getOrdersList() {
      const { data } = await this.$http.get("orders", {
        params: this.queryInfo
      });
      if (data.meta.status !== 200) return;
      this.ordersList = data.data.goods;
      this.total = data.data.total;
      console.log(this.ordersList);
    },
    //每页条数发生变化
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getOrdersList();
    },
    //页数发生变化
    handleCurrentChange(newNum) {
      this.queryInfo.pagenum = newNum;
      this.getOrdersList();
    },
    // 修改表单的对话框
    editFrom() {
      this.editDialogVisible = true;
    },
    // 物流信息的对话框
    async physicaFrom() {
      const { data } = await this.$http.get("/kuaidi/1106975712662");
      if (data.meta.status !== 200) return;
      this.physicaList = data.data;
      console.log(this.physicaList);
      
      this.physicalDialogVisible = true;
    }
  },
  created() {
    this.getOrdersList();
  }
};
</script>

<style lang="less" scoped>
@import '../../plugins/timeline/timeline.css';
@import '../../plugins/timeline-item/timeline-item.css';
.el-cascader {
  width: 100%;
}
</style>